#!/bin/bash

set -o errexit

test_dir=$(realpath $(dirname $0))
. ${test_dir}/../functions

set_debug

main() {
	create_infra $namespace

	cluster="some-name"
	spinup_pxc "$cluster" "$conf_dir/$cluster.yml"
	keyring_plugin_must_not_be_in_use "$cluster"
	table_must_not_be_encrypted "$cluster" "myApp"

	run_backup "$cluster" "on-demand-backup-pvc"
	if [ -z "$SKIP_REMOTE_BACKUPS" ]; then
		run_backup "$cluster" "on-demand-backup-aws-s3"
	fi

	vault1="vault-service-1-${RANDOM}"
	start_vault $vault1
	run_recovery_check "$cluster" "on-demand-backup-pvc"
	check_pvc_md5
	keyring_plugin_must_be_in_use "$cluster"
	table_must_not_be_encrypted "$cluster" "myApp"

	if [ -z "$SKIP_REMOTE_BACKUPS" ]; then
		run_recovery_check "$cluster" "on-demand-backup-aws-s3"
		keyring_plugin_must_be_in_use "$cluster"
		table_must_not_be_encrypted "$cluster" "myApp"
	fi

	helm uninstall $vault1 || :
	kubectl_bin delete --grace-period=0 --force=true namespace $vault1 &
	destroy $namespace
	desc "test passed"
}

main
